﻿#include "svgwriter.h"
#include "svgshape.h"

#include <gtest/gtest.h>

class SvgWriterTest : public testing::Test
{
protected:
	SvgWriterTest()
		:stream(&str)
	{
	}

	QString str;
	QTextStream stream;
};

TEST_F(SvgWriterTest, empty)
{
	SvgWriter writer({}, stream, 500, 500);
	writer.SetBackground(Qt::white);
	writer.Save();

	EXPECT_EQ(str,
		R"svg(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" subset="wps" height="500" width="500">)svg"
		R"svg(<rect x="0" y="0" width="500" height="500" stroke="rgb(255, 255, 255, 1)" stroke-width="2" fill="rgb(255, 255, 255, 1)"/></svg>)svg");
}

TEST_F(SvgWriterTest, one_line)
{
	auto line = std::make_unique<SvgLine>(QLineF{{111, 222}, {444, 555}});

	SvgShapeVec shapes;
	shapes.push_back(std::move(line));

	SvgWriter writer(shapes, stream, 500, 500);
	writer.SetBackground(Qt::white);
	writer.Save();

	EXPECT_EQ(str,
		R"svg(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" subset="wps" height="500" width="500">)svg"
		R"svg(<rect x="0" y="0" width="500" height="500" stroke="rgb(255, 255, 255, 1)" stroke-width="2" fill="rgb(255, 255, 255, 1)"/>)svg"
		R"svg(<line x1="111" y1="222" x2="444" y2="555" stroke="rgb(0, 0, 0, 1)" stroke-width="2"/></svg>)svg"
		);
}

TEST_F(SvgWriterTest, one_rect)
{
	auto rect = std::make_unique<SvgRect>(QRectF{QPointF{61.5, 109.5}, QSizeF{127, 86}});
	rect->Brush().setColor(QColor{255, 255, 255, 0});

	SvgShapeVec shapes;
	shapes.push_back(std::move(rect));

	SvgWriter writer(shapes, stream, 500, 500);
	writer.SetBackground(Qt::white);
	writer.Save();

	EXPECT_EQ(str,
		R"svg(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" subset="wps" height="500" width="500">)svg"
		R"svg(<rect x="0" y="0" width="500" height="500" stroke="rgb(255, 255, 255, 1)" stroke-width="2" fill="rgb(255, 255, 255, 1)"/>)svg"
		R"svg(<rect x="61.5" y="109.5" width="127" height="86" stroke="rgb(0, 0, 0, 1)" stroke-width="2" fill="rgb(255, 255, 255, 0)"/></svg>)svg"
		);
}
